package tesis.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public final class PropertyUtils {

    private static final Properties messagesProperties;
    private static final Properties appProperties;
    private static final String APP_MESSAGES_PROPERTIES = "messages.properties";
    private static final String APP_PROPERTIES = "properties/tesis/prototipo/prototipo.properties";
    private static final Logger LOG = LoggerFactory.getLogger(PropertyUtils.class);

    static {
        messagesProperties = new Properties();
        appProperties = new Properties();
        try {
            InputStream messagesStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(APP_MESSAGES_PROPERTIES);
            InputStream appStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(APP_PROPERTIES);
            messagesProperties.load(messagesStream);
            appProperties.load(appStream);
        } catch (IOException ie) {
            LOG.error("No se pudo inicializar el PropertyUtils", ie);
        } catch (Exception ex) {
            LOG.error("No se pudo inicializar el PropertyUtils", ex);
        }
    }

    private PropertyUtils() {
    }

    /**
     * Lee del archivo mesages.properties
     * @param key del property
     * @return value del property
     */
    public static String getMessagesProperty(String key) {
        return (messagesProperties == null) ? null : messagesProperties.getProperty(key);
    }

    /**
     * Lee del archivo gestion_tramite_gfhl.properties
     * @param key del property
     * @return value del property
     */
    public static String getAppProperty(String key) {
        return (appProperties == null) ? null : appProperties.getProperty(key);
    }
}
